POV-Ray : Newsgroups : povray.newusers : Onion : Re: Onion Server Time
28 Jul 2024 14:22:13 EDT (-0400)
  Re: Onion  
From: Matija
Date: 15 Feb 2009 12:25:00
Message: <web.49984f6d272aa89be30e02620@news.povray.org>
> Hi,
>
> There are quite a few things wrong with this. Some are coding errors, but I
> think you also run into a problem that arises when using cutaway_textures on
> more complex CSG objects.
>
> Firstly, your Onion declaration is started, the loop is started and, on the
> first iteration, the difference between the two spheres is assigned to
> 'Onion'. This ends the Onion definition, but the loop continues. All
> subsequent iterations add a new difference directly into the scene and these
> objects are never intersected with the box, so you only see the outer
> surface of the outermost sphere. No pigment is assigned to this sphere, so
> it looks black. To fix this you can declare the Onion as a union of
> everything generated by the while loop (see below).
>
> The cutaway_textures keyword on the differenced spheres has no effect as the
> object has no texture defined by that time.
> The cutaway_textures keyword can be added to the intersection, but it
> doesn't seem to work well with complex CSG objects, which I think is a known
> problem.
>
> The following example uses an onion pigment and a color_map to texture the
> whole object, which aviods this problem for the particular shape you have,
> but which probably won't work well with other shapes.
>
> Another alternative would be to declare the box first. Then loop through and
> do the intersection of that box with each sphere inside the loop in turn,
> before applying a unique color to each shell.
>
> Regards,
> Chris B.
>
> #declare Stevec=1;
> #declare Rad1 = 1;
> #declare Rad2 = 0.1;
>
> #declare Onion = union {
>   #while (Stevec >= 0.2)
>     #declare Rad1=Stevec;
>     #declare Rad2=Rad1-0.1;
>     difference {
>       sphere {<0,0,0>, Rad1}
>       sphere {<0,0,0>, Rad2}
>     }
>     #declare Stevec=Stevec-0.2;
>   #end
> }
>
> difference {
>   object {Onion }
>   box {<0,-1,-1>,<1,1,1>}
>   pigment {onion
>     color_map {
>       [0.00 0.05 color White  color White ]
>       [0.05 0.25 color Red    color Red   ]
>       [0.25 0.45 color Yellow color Yellow]
>       [0.45 0.65 color Green  color Green ]
>       [0.65 0.85 color Blue   color Blue  ]
>       [0.85 1.10 color White  color White ]
>     }
>   }
> }
Chris,

Thank you very much for your help!

I tried to use cutaway_textures, because I was hoping that would fix the problem
of the black sphere for some reason. I saw this thread:

http://news.povray.org/povray.newusers/thread/%3Cweb.4996becdd7a07582a386ad060%40news.povray.org%3E/

and thought it might help.

Thanks a lot for your analysis and the solution. It is confusing for a beginner
to use #declare sometimes, especially for objects. For variables, the statement
ends with ; but for object definitions it seems like there is no way to conclude
the #declare statement.

Also, the fact that the loop adds more subtractors to the first sphere with each
repeating "difference" statement is sort of unexpected for me. I thought each
statement would be treated separately, because the "difference" statement was
closed by the {} brackets.

Regards,

Matija


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.